Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique_id field to product #47364

Merged
merged 24 commits into from
Jul 3, 2024
Merged

Add unique_id field to product #47364

merged 24 commits into from
Jul 3, 2024

Conversation

nathanss
Copy link
Contributor

@nathanss nathanss commented May 10, 2024

Submission Review Guidelines:

Changes proposed in this Pull Request:

Adds a new "unique id" field to the new product editor. The field accepts any type of input, at least for now.

Closes #41816
Closes #39577

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. If you're running locally, please deactivate and activate the WooCommerce plugin, as this adds a new column in the wp_wc_product_meta_lookup table.
  2. Enable the new product editor at /wp-admin/admin.php?page=wc-settings&tab=advanced&section=features
  3. Go to Products > Add
  4. Go to the 'Inventory' tab
  5. Check the field labeled "GTIN, UPC, EAN OR ISBN"
  6. You should be able to type any string into it.
  7. It should save correctly.
  8. Create another product
  9. Fill in the name, and try to type the same value as you typed before for GTIN, UPC, EAN OR ISBN
  10. Try to publish
  11. An error should occur, as we don't allow duplicated values.

Changelog entry

  • Automatically create a changelog entry from the details below.

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Comment

@nathanss nathanss marked this pull request as draft May 10, 2024 13:25
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label May 10, 2024
Copy link
Contributor

github-actions bot commented May 10, 2024

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Test this pull request with WordPress Playground.

Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.

@nathanss nathanss self-assigned this Jun 20, 2024
@nathanss nathanss marked this pull request as ready for review June 20, 2024 17:51
@nathanss nathanss requested review from a team and octaedro June 20, 2024 18:52
Copy link
Contributor

github-actions bot commented Jun 20, 2024

Hi @louwie17,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Copy link
Contributor

@octaedro octaedro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job @nathanss! This is testing well here and the code LGTM.

However, I would like to ask a couple of questions. After answering them, I think this PR will be ready to go.

  • Could the unique_id be repeated? I mean, now it is possible to have them duplicated, but I was wondering if that was expected.
  • The SKU will continue being unique, right? Maybe we can add a comment explaining that briefly because the naming is not very intuitive.

@nathanss
Copy link
Contributor Author

@octaedro these are all relevant questions, which I'll be redirecting to the product team @pmcpinto @j111q

Are we OK merging this in the state it is right now (which fulfills the acceptance criteria described in #39577), and adding additional features later? Or should we revisit this?

Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the unique_id be repeated? I mean, now it is possible to have them duplicated, but I was wondering if that was expected.

This does seem like a critical piece we want to implement from the start, and something that is easier to implement now and than later on revert, versus the other way around.
I would say given this is a unique id, we should have it act similar as a SKU and not allow duplicates across products.
Did any of this come up in the discussions? or P2 conversations?

'type' => 'string',
'context' => array( 'view', 'edit' ),
),
'unique_id' => array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm should the description here for unique_id be: 'GTIN, UPC, EAN or ISBN' ?
And we keep 'Unique identifier.' for the sku field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with renaming the unique_id field, but I think we should avoid saying that sku is an 'Unique identifier', since we're introducing a new field with this name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for clarification: sku is unique at the store level vs. the new field shall hold a globally unique identifier such as GTIN.
Hence, the proposed new unique_id would also be unique at the store level.
Maybe calling it global_unique_id could be more explicit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it. I will rename it

@pmcpinto
Copy link
Collaborator

This does seem like a critical piece we want to implement from the start, and something that is easier to implement now and than later on revert, versus the other way around.
I would say given this is a unique id, we should have it act similar as a SKU and not allow duplicates across products.

I agree that we should avoid duplications.

Copy link
Contributor

github-actions bot commented Jun 24, 2024

Size Change: +37 B (0%)

Total Size: 2.49 MB

compressed-size-action

Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work @nathanss, it tested well!
I left a couple small comments, but for the rest this looks great!

/**
* Get Unique ID.
*
* @since 9.0.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be updated to 9.1 as well

@@ -535,7 +541,12 @@ public function get_item_schema() {
'readonly' => true,
),
'sku' => array(
'description' => __( 'Unique identifier.', 'woocommerce' ),
'description' => __( 'SKU.', 'woocommerce' ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we still keep this as 'Unique identifier.'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer keeping it like this, to avoid confusion with the new field, though I don't think this description is a big deal. I'll update it to Stock Keeping Unit, is that OK?

@@ -987,7 +992,12 @@ public function get_item_schema() {
'context' => array( 'view', 'edit' ),
),
'sku' => array(
'description' => __( 'Unique identifier.', 'woocommerce' ),
'description' => __( 'SKU.', 'woocommerce' ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above.

Copy link
Member

@MatthiasReinholz MatthiasReinholz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @nathanss , I tested this and it looks good to me!

I have two questions:

  • The new field is only available on the new product editor, correct?
  • Will the global_unique_id be populated to the REST API?

@nathanss
Copy link
Contributor Author

nathanss commented Jul 2, 2024

@MatthiasReinholz

The new field is only available on the new product editor, correct?

Yes, currently, that is correct.

Will the global_unique_id be populated to the REST API?

It is added to the REST API. The new product editor consumes the REST API, so it will be available there immediately.

@nathanss nathanss requested a review from louwie17 July 2, 2024 22:28
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the API description updates using Stock Keeping Unit. seems good with me.
I tested this again and it seems to test well, nice work, I also noticed that the wcadmin_product_add_publish track includes the global_unique_id id 👍

@nathanss nathanss merged commit 85cedf2 into trunk Jul 3, 2024
40 checks passed
@nathanss nathanss deleted the poc/unique_id_field branch July 3, 2024 14:45
@github-actions github-actions bot added this to the 9.2.0 milestone Jul 3, 2024
@github-actions github-actions bot added the needs: analysis Indicates if the PR requires a PR testing scrub session. label Jul 3, 2024
mattsherman pushed a commit that referenced this pull request Jul 3, 2024
* Add unique_id field to product

* Fix documentation

* Fix wrong comment

* Update description

* Add unique_id for variations

* Update lint

* Update tests

* Add changelog

* Update variations unit test

* Add unique_id to wc_product_meta_lookup

* Add unique_id methods to cpt interface

* Add new methods for unique_id and add it to lookup table

* Add unique_id functions to product functions

* Throw error when unique_id is duplicated

* Handle error message for unique_id on the front-end

* Add changelog

* Rename unique_id description in REST API

* Fix lint issues

* Add unique_id tracking for product publish

* Rename to 'global_unique_id'

* Fix lint

* Fix lint

* Bump documentation version

* Update controller description of fields
@Stojdza Stojdza added needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. status: analysis complete Indicates if a PR has been analysed by Solaris and removed needs: analysis Indicates if the PR requires a PR testing scrub session. labels Jul 8, 2024
mikejolley pushed a commit that referenced this pull request Jul 10, 2024
* Add unique_id field to product

* Fix documentation

* Fix wrong comment

* Update description

* Add unique_id for variations

* Update lint

* Update tests

* Add changelog

* Update variations unit test

* Add unique_id to wc_product_meta_lookup

* Add unique_id methods to cpt interface

* Add new methods for unique_id and add it to lookup table

* Add unique_id functions to product functions

* Throw error when unique_id is duplicated

* Handle error message for unique_id on the front-end

* Add changelog

* Rename unique_id description in REST API

* Fix lint issues

* Add unique_id tracking for product publish

* Rename to 'global_unique_id'

* Fix lint

* Fix lint

* Bump documentation version

* Update controller description of fields
@peterfabian peterfabian added the release: highlight Issues that have a high user impact and need to be discussed/paid attention to. label Jul 12, 2024
thealexandrelara pushed a commit that referenced this pull request Jul 18, 2024
* Add unique_id field to product

* Fix documentation

* Fix wrong comment

* Update description

* Add unique_id for variations

* Update lint

* Update tests

* Add changelog

* Update variations unit test

* Add unique_id to wc_product_meta_lookup

* Add unique_id methods to cpt interface

* Add new methods for unique_id and add it to lookup table

* Add unique_id functions to product functions

* Throw error when unique_id is duplicated

* Handle error message for unique_id on the front-end

* Add changelog

* Rename unique_id description in REST API

* Fix lint issues

* Add unique_id tracking for product publish

* Rename to 'global_unique_id'

* Fix lint

* Fix lint

* Bump documentation version

* Update controller description of fields
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: external testing Indicates if the PR requires further testing conducted by testers external to the development team. plugin: woocommerce Issues related to the WooCommerce Core plugin. release: highlight Issues that have a high user impact and need to be discussed/paid attention to. status: analysis complete Indicates if a PR has been analysed by Solaris
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SPIKE: Add product ID field to the new product form Add product ID field to the new product form
7 participants